<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org" xmlns:cb="http://www.ossbar.com/">
<head th:include="layout/head" />
<div th:include="layout/foot"></div>
<script type="text/javascript" th:inline="javascript">
	cb.loadmodules([ "validate", "ajax", "lay", "ztree","jqgrid","contextmenu"]);
	$(document).ready(function() {
		$('body').layout({
			applyDefaultStyles : true,
			west__size:250,
			west__closable:false
		});
	});
	var pid;
	var parentId;
	var ptypecode;
	function showMail(e, treeId, treeNode){
		var ptype = treeNode.type;
		ptypecode = ptype=="02"?treeNode.cbid:ptype=="01"?"INBOX":"FOLD";
		pid = ptype=="01"?treeNode.cbid:treeNode.code;
		if(ptypecode == "FOLD"){
			parentId = treeNode.cbid;
		}
		$("#resForm").load(cb.baseurl + "mail/tmaildetail/listdetail");
	}
</script>
<body>
	<div class="ui-layout-west">
		<cb:tree id="orgTree" url="/mail/tmaildetail/mailtree" rootNode="{'name':'邮箱账户'}"
			mapper="{'name':'name','type':'type','code':'code','parentId':'parentId','parentValue':-1,'cbid':'id'}"
			onClick="showMail" expandAll="0"
			treeStyle="position:fixed;border:0px;top:0px;left:0px;bottom:0px;width:250px;height:auto;" />
		<cb:contextmenu contentId="orgTree" id="orgMenu"
		 menus="[{title:'重命名',click: function(){renameFold();}},
		 {title:'删除',click: function(){delFold();}},
		 {title:'新增文件夹',click: function(){createFold();}}]"/>
	</div>
	<div class="ui-layout-center">
		<div id="resForm"></div>
	</div>
</body>
<script type="text/javascript" th:inline="javascript">
	$("#resForm").load(cb.baseurl + "mail/tmaildetail/listdetail");
	function renameFold(){
		if((parentId||"") == ""){
			cb.alert("请先选择要重命名的文件夹");
			return false;
		}
		if(parentId == "-1"){
			cb.alert("系统默认文件夹不允许重命名");
			return false;
		}
		cb.winopen('重命名', '700px', '300px', 'mail/tmailfold/edit?id='+(parentId||""), 'yes',
				function() {
			cb.trees["orgTree"].load();
				});
	}
	function delFold(){
		if((parentId||"") == ""){
			cb.alert("请先选择要删除的文件夹");
			return false;
		}
		if(parentId == "-1"){
			cb.alert("系统默认文件夹不允许删除");
			return false;
		}
		cb.confirm("删除文件夹会同步将文件下的所有邮件都删除，确定删除该文件夹吗？",function(){
			cb.post("mail/tmailfold/remove","id="+parentId,function(result){
				if(result.err){
					cb.alert(result.err);
				}else{
					cb.alert("删除成功",function(){
						cb.trees["orgTree"].load();
					});
				}
			});
			
		})
	}
	function createFold(){
		if((pid||"") == ""){
			cb.alert("请先选择邮箱账户或者个人文件夹");
			return false;
		}
		cb.winopen('新增文件夹', '700px', '300px', 'mail/tmailfold/add?maId='+(pid||"")+"&parentId="+(parentId||""), 'yes',
				function() {
			cb.trees["orgTree"].load();
				});
	}
</script>
</html>